package day66_677;

import java.util.HashMap;

/**
 * @ClassName MapSum
 * @Description TODO
 * @Author clockTown
 * @Date 2021/7/14 20:33
 * @Version 1.0
 */
public class MapSum {

    HashMap<String, Integer> map;

    public MapSum() {
        map = new HashMap<>();
    }

    public void insert(String key, int val) {
        map.put(key, val);
    }

    public int sum(String prefix) {
        int sum = 0;
        for (String s : map.keySet()) {
            if (s.startsWith(prefix)) {
                sum += map.get(s);
            }
        }
        return sum;
    }
}

/**
 * Your MapSum object will be instantiated and called as such:
 * MapSum obj = new MapSum();
 * obj.insert(key,val);
 * int param_2 = obj.sum(prefix);
 */
